<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>企业列表</title>

    <jsp:include page="${pageContext.request.contextPath}/common/css.jsp"/>
</head>
<body>
    <div class="container">
        <div class="row">
            <ol class="breadcrumb">
                <li><a href="#">主页</a></li>
                <li><a href="#">企业列表</a></li>
            </ol>
        </div>
        <div class="row">
            <form class="form-inline" action="${pageContext.request.contextPath}/company/list">
                <div class="form-group">
                    <label for="likeName">企业名称</label>
                    <input type="text" class="form-control" name="likeName" id="likeName"
                           placeholder="请输入要查询的企业名称" size="30" value="${likeName}">
                    <input type="hidden" name="pageNo" id="pageNo">
                    <input type="hidden" id="pageCount" value="${pageCount}">
                </div>
                <button type="submit" class="btn btn-default">搜索</button>
            </form>
        </div>

    <c:if test="${empty companies}">
        <h2 style="line-height: 300px; text-align: center" class="warning">
            没有指定的企业信息，请重新搜索！
        </h2>
    </c:if>
    <c:if test="${!empty companies}">
        <div class="row">
            <div class="col-md-12">
        <table class="table">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>企业名称</th>
                    <th>所在城市</th>
                    <th>信息来源</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <%--
                    items:遍历的集合对象（需要使用EL表达式获取）
                    var:定义每次遍历出来的元素名称，并且JSTL自动将该对象放入作用域
                    begin:从集合的哪个下标开始
                    end:遍历到哪个下标元素
                    varStatus:定义包含了循环的状态信息的对象的名称
                    step:循环的步长，默认为1
                --%>
                <c:forEach items="${companies}" var="company"  varStatus="status" >
                    <tr>
                        <td>${status.count}</td>
                        <td>${company.name}</td>
                        <td>${company.city}</td>
                        <td>
                            <c:choose>
                                <c:when test="${company.sourceId eq 1}">网络</c:when>
                                <c:when test="${company.sourceId eq 2}">QQ/微信</c:when>
                                <c:when test="${company.sourceId eq 3}">电话</c:when>
                                <c:otherwise>其它</c:otherwise>
                            </c:choose>
                        </td>
                        <td>
                            <%--
                                value:要格式化的时间对象
                                pattern:时间格式化字符串（使用模式字母）
                            --%>
                            <fmt:formatDate value="${company.updateTime}" pattern="yyyy-MM-dd HH:mm" />
                        </td>
                        <td>
                            <a class="btn btn-default"
                               href="
                                <c:url value="${pageContext.request.contextPath}/company/update">
                                    <c:param name="id" value="${company.id}"/>
                                </c:url>
                                ">修改

                            </a>&nbsp;&nbsp;&nbsp;&nbsp;
                            <a class="btn btn-default"
                               href="javascript:deleteCompany('${company.id}','${company.name}');">删除</a>
                        </td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
            </div>
        </div>
        <%--动态导入工具页--%>
        <c:import url="${pageContext.request.contextPath}/common/pager.jsp">
            <c:param name="totalCount" value="${totalCount}"/>
        </c:import>
    </c:if>



    </div>
    <jsp:include  page="${pageContext.request.contextPath}/common/js.jsp" />

    <script>
        function deleteCompany(id,name){
            if (confirm("你确定要删除'"+name+"'吗？")){
                location.href="${pageContext.request.contextPath}/company/delete?id="+id;
            }
        }
    </script>
</body>
</html>
